<template>
  <div class="content">
    <!--    数据字典公共列表弹窗-->
    <el-dialog
      v-dialogDrag
      :title="$t('market.infoList')"
      model
      :visible.sync="isclientlDialog"
      :close-on-click-modal="false"
      width="60%"
      top="5vh"
      :before-close="handleClose"
    >
      <div>
        <div class="materiel-form">
          <span class="materiel-code">{{ $t('shop.name1') }}</span>
          <el-input v-model.trim="fname" class="input-width" size="mini" placeholder="请输入名称" @keyup.enter.native="getBasicUnit" />
          <el-button size="mini" type="primary" @click="getBasicUnit">{{ $t('btn.search') }}</el-button>
          <el-button v-if="msg==='SX_FIN_BAFTYPE_WLDW'" size="mini" type="primary" @click="addWldw">{{ $t('btn.add') }}</el-button>
        </div>
        <jc-table
          :table-data="tableData"
          :table-header="tableHeader"
          table-height="53vh"
          serial
          @clickRow="clientlSelectRow"
        />
      </div>

    </el-dialog>
  </div>
</template>
<script>
import { queryViewItem } from '@/api/marketManage/marketOrder'

export default {
  props: {
    msg: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      fname: '',
      isclientlDialog: true,
      tableData: [],
      tableHeader: [
        { label: this.$t('market.dataName'), prop: 'fname' },
        { label: this.$t('shop.fnumber'), prop: 'fnumber' },
        { label: this.$t('market.descrip'), prop: 'fdescripTion' },
        { label: this.$t('shop.type'), prop: 'typeName' }
      ],
      prodValue: { fcustId: '', fname: '', isclientlDialog: true }
    }
  },
  created() {
    this.getBasicUnit()
  },
  methods: {
    // 基本单位
    async getBasicUnit() {
      const DATA = {
        viewName: this.msg,
        fname: this.fname,
        isAll: this.msg === 'SX_V_BASEUNIT' ? 1 : 0
      }
      const { data: RES } = await queryViewItem(DATA)
      this.tableData = RES.list
    },
    // 新增
    addWldw() {
      this.$router.push({ path: '/comeGounit' })
      this.$emit('unit', this.prodValue)
    },
    // 单位选中
    clientlSelectRow(item) {
      this.prodValue = item
      this.$emit('unit', this.prodValue)
    },
    // 关闭前回调
    handleClose() {
      this.prodValue.isclientlDialog = false
      this.$emit('unit', this.prodValue)
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  @include listBom;
}
</style>
